home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-08-04 | 3.7 KB | 178 lines | [TEXT/CWIE] |
- // >>> ⌐ 1996-1997 Microsoft Corporation. All rights reserved. <<<
- #define _MAC
- #include <ole2.h>
- #include <dispatch.h>
- #include "Util.h"
-
- Handle FileURLFromFileSpec (FSSpec* FileSpec)
- {
- CInfoPBRec myPB; // parameter block for PBGetCatInfo
- Str255 dirName; // a directory name
- OSErr myErr;
- Int32 NameLen = 0;
- Int32 PathLen = 256;
- Handle tempPathHdl = NewHandleClear(256);
- char* tempPath;
- char FileURL[16] = "file:///";
- Int16 move;
-
- if(tempPathHdl == NULL)
- return NULL;
-
- HLock(tempPathHdl);
- tempPath = *tempPathHdl;
-
- tempPath[0] = 0; // initialize full pathname}
- myPB.hFileInfo.ioNamePtr = &dirName[0];
- myPB.hFileInfo.ioVRefNum = FileSpec->vRefNum; // indicate target volume
- myPB.dirInfo.ioDrParID = FileSpec->parID; // initialize parent directory ID
- myPB.dirInfo.ioFDirIndex = -1; // get info about a directory
-
- p2cstr(FileSpec->name);
- strcat(tempPath, (char*)FileSpec->name);
- c2pstr((char*)FileSpec->name);
- NameLen = strlen(tempPath);
- // Get name of each parent directory, up to root directory.
- do
- {
- myPB.dirInfo.ioDrDirID = myPB.dirInfo.ioDrParID;
- myErr = PBGetCatInfoSync(&myPB);
- p2cstr(dirName);
-
- // make sur string is long enough
- while((strlen((char*)dirName) + NameLen) > (PathLen + 2)) // room for name, colon and termintating 0
- {
- PathLen += 256;
- HUnlock(tempPathHdl);
- SetHandleSize(tempPathHdl, PathLen);
- if(tempPathHdl == NULL)
- return NULL;
-
- HLock(tempPathHdl);
- tempPath = *tempPathHdl;
-
- }
- move = strlen((char*)dirName) + 1;
-
- // move existing string to make room for new folder name and ":"
- BlockMove(tempPath, (char*)&tempPath[move], NameLen);
- strcat((char*)dirName, "/");
- move = strlen((char*)dirName);
- BlockMove(dirName, tempPath, move);
- NameLen += strlen((char*)dirName);
- }
- while( myPB.dirInfo.ioDrDirID != fsRtDirID);
-
- // add the file URL prefix
- move = strlen((char*) FileURL);
-
- if ( (NameLen + move) > GetHandleSize(tempPathHdl) )
- {
- HUnlock(tempPathHdl);
- SetHandleSize(tempPathHdl, GetHandleSize(tempPathHdl) + 256);
- if(tempPathHdl == NULL)
- return NULL;
- HLock(tempPathHdl);
- tempPath = *tempPathHdl;
- }
-
- // move existing string to make room for new folder name and ":"
- BlockMove(tempPath, (char*)&tempPath[move], NameLen);
- BlockMove(FileURL, tempPath, move);
-
- HUnlock(tempPathHdl);
-
- return tempPathHdl;
- }
-
-
- void VarTypeToName(VARTYPE Type, Str255 TypeStr)
- {
- switch ( Type )
- {
- case VT_EMPTY:
- CopyPString(TypeStr, "\pvoid");
- break;
-
- case VT_BSTR:
- CopyPString(TypeStr, "\pString");
- break;
-
- case VT_BOOL:
- CopyPString(TypeStr, "\pBoolean");
- break;
-
- case VT_ERROR:
- CopyPString(TypeStr, "\pAXErrorCode");
- break;
-
- case VT_I2:
- CopyPString(TypeStr, "\pInt16");
- break;
-
- case VT_UI2:
- CopyPString(TypeStr, "\pUint16");
- break;
-
- case VT_I4:
- CopyPString(TypeStr, "\pInt32");
- break;
-
- case VT_UI4:
- CopyPString(TypeStr, "\pUint32");
- break;
-
- case VT_R4:
- CopyPString(TypeStr, "\pReal32");
- break;
-
- case VT_R8:
- CopyPString(TypeStr, "\pReal64");
- break;
-
- case VT_INT:
- CopyPString(TypeStr, "\pINT");
- break;
-
- case VT_UINT:
- CopyPString(TypeStr, "\pUINT");
- break;
-
- case 14:
- CopyPString(TypeStr, "\pFixed");
- break;
-
- case VT_I1:
- CopyPString(TypeStr, "\pChar8");
- break;
-
- case VT_UI1:
- CopyPString(TypeStr, "\pUchar8");
- break;
-
- case VT_DATE:
- CopyPString(TypeStr, "\pDate");
- break;
-
- case VT_UNKNOWN:
- CopyPString(TypeStr, "\pIUnknown*");
- break;
-
- case VT_DISPATCH:
- CopyPString(TypeStr, "\pIDispatch*");
- break;
-
- default:
- CopyPString(TypeStr, "\p-");
- break;
- }
- }
-
-
- void CopyPString(StringPtr DestStr, StringPtr SourceStr)
- {
- BlockMove(SourceStr, DestStr, SourceStr[0]+1);
- }
-
-
-